package logic

import (
	"context"
	"property/mysql"

	"property/prorpc/internal/svc"
	"property/prorpc/prorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseAddLogic) HouseAdd(in *prorpc.HouseAddRequest) (*prorpc.HouseAddResponse, error) {
	// todo: add your logic here and delete this line

	house := mysql.House{
		Name:    in.Name,
		Address: in.Address,
		Price:   float64(in.Price),
	}
	mysql.DB.Debug().Create(&house)

	return &prorpc.HouseAddResponse{
		HouseId: int64(house.ID),
	}, nil
}
